home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
inlin219.zip
/
UNINLINE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-09-27
|
23KB
|
838 lines
{$R-} {Range checking off}
{$B-} {Boolean short circuiting off}
{$S-} {Stack checking off}
{$I+} {I/O checking on}
{$N-} {No numeric coprocessor}
{$V-} {Relaxed String Checking}
{$M 65500,16384,655360} {Turbo 3 default stack and heap}
{UNINLINE7}
(********* Source code Copyright 1986, by L. David Baldwin *********)
{
Version 1.1. Convert to Turbo 4.
}
program Inline_disasm;
Uses
Crt;
Const
Tab = 9;
Signon1 : String[35] = ^M^J'Inline Disassembler, Vers 1.1'^M^J;
Signon2 : String[40] = '(C) Copyright 1986 by L. David Baldwin'^M^J;
Ulen=80;
Symbolleng=28;
MaxByte=Maxint;
Tokenleng=7;
MaxLabels=300;
PhraseOk=True;
FirstTab=7;
SecondTab=15;
Type
Byteptr=^Byte;
Ptrrec=Record R,S :Word; end;
String8=String[8];
String127=String[127];
String2=Array[1..2] of Char;
Filestring=String[64];
Regstrtype=Array[0..15] of Array[1..2] of Char;
Segregtype=Array[0..3] of Array[1..2] of Char;
{Packet holds a displacement which may be either in phrase form (symbolic
expression) or numeric form. It may be of byte or word size}
Packet =Record
Dispsize :(Bytesize,Wordsize);
case Phrase : Boolean of {either a numeric or symbollic phrase}
True :(S :String[Symbolleng]);
False :(Value : Integer);
end;
Line = Record {Disassembled instruction is built up in a 'line'}
case Boolean of
True: (S:String[Ulen]);
False :(Len : Byte; PCsave : Integer);
end;
Var
Ustring : Line;
Chi,PC,PCstart,PCfinish : Integer;
NValue :Word;
Token : String[Tokenleng];
Pair : String2;
LCh : Char Absolute Pair;
UCh :Char;
St :String127;
Symname:String[Symbolleng];
EofInf,BytePending,Firsttime,Wd,ToReg,PrefixFl,Wait_Found : Boolean;
Reg,Mode,Rm : Word;
Opcode,PendingByte :Byte;
UsIndex,TIndex,LabelIndx,ErrCount : Integer;
TextArray : Array[0..MaxByte] of Char;
Inf,Outf : Text;
Labels : Array[0..MaxLabels] of Record {Holds info on needed labels}
PCvalue : Integer; Found : Boolean;
end;
Const Opcodes : Array[0..$FF] of Byte = (
5,5,5,5,5,5,73,71,69,69,69,69,69,69,73,20,
4,4,4,4,4,4,73,71,86,86,86,86,86,86,73,71,
6,6,6,6,6,6,24,18,97,97,97,97,97,97,16,19,
102,102,102,102,102,102,91,0,13,13,13,13,13,13,23,3,
29,29,29,29,29,29,29,29,21,21,21,21,21,21,21,21,
73,73,73,73,73,73,73,73,71,71,71,71,71,71,71,71,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
49,46,34,41,37,43,35,42,51,48,50,47,38,44,39,45,
20,20,20,20,98,98,100,100,62,62,62,62,62,54,62,71,
67,100,100,100,100,100,100,100,8,17,7,99,74,72,84,52,
62,62,62,62,63,64,14,15,98,98,95,96,57,58,87,88,
62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,
20,20,80,80,55,53,62,62,20,20,81,81,32,30,31,33,
20,20,20,20,2,1,20,101,20,20,20,20,20,20,20,20,
61,60,59,36,28,28,70,70,7,40,40,40,28,28,70,70,
56,20,79,78,25,12,20,20,9,92,11,94,10,93,20,20);
Const Grp1_2names : Array[0..15] of Byte =
(98,75,68,66,65,27,22,26,29,21,7,7,40,40,73,75);
Const Shiftnames : Array[0..7] of Byte =(82,83,76,77,89,90,75,85);
Const Immednames : Array[0..7] of Byte = (5,69,4,86,6,97,102,13);
Const Instrnames : Array[0..102] of String[6] = (
'AAA', 'AAD', 'AAM', 'AAS', 'ADC', 'ADD', 'AND', 'CALL', 'CBW', 'CLC',
'CLD', 'CLI', 'CMC', 'CMP', 'CMPSB','CMPSW','CS:', 'CWD', 'DAA', 'DAS',
'DB', 'DEC', 'DIV', 'DS:', 'ES:', 'HLT', 'IDIV', 'IMUL', 'IN', 'INC',
'INT', 'INTO', 'INT 3','IRET', 'JB', 'JBE', 'JCXZ', 'JZ', 'JL', 'JLE',
'JMP', 'JNB', 'JA', 'JNZ', 'JGE', 'JG', 'JNO', 'JPO', 'JNS', 'JO',
'JPE', 'JS', 'LAHF', 'LDS', 'LEA', 'LES', 'LOCK', 'LODSB','LODSW','LOOP',
'LOOPE','LOOPNE','MOV', 'MOVSB','MOVSW','MUL', 'NEG', 'NOP', 'NOT', 'OR',
'OUT', 'POP', 'POPF', 'PUSH', 'PUSHF','???', 'RCL', 'RCR', 'REPE', 'REPNE',
'RET', 'RETF', 'ROL', 'ROR', 'SAHF' ,'SAR', 'SBB', 'SCASB','SCASW','SHL',
'SHR', 'SS:', 'STC', 'STD', 'STI', 'STOSB','STOSW','SUB', 'TEST', 'WAIT',
'XCHG', 'XLAT', 'XOR');
Const RegStr : Regstrtype = (
'AX','CX','DX','BX','SP','BP','SI','DI',
'AL','CL','DL','BL','AH','CH','DH','BH');
SegRegStr : Segregtype = ('ES','CS','SS','DS');
{-------------OutUstring}
PROCEDURE OutUstring;
Var Tmp : Integer;
begin
(* WriteLn(Ustring.S); *)
if TIndex < MaxByte-Ulen then
begin
Tmp:=Ustring.Len+1;
Move(Ustring, TextArray[TIndex], Tmp);
TIndex:=TIndex+Tmp;
end
else
begin
WriteLn('Output Array Overflow');
Halt(1);
end;
end;
{-------------Error}
PROCEDURE Error(II :Integer; S :String127);
Var X,Y : Integer;
NewS : String127;
begin
GotoXY(1,WhereY);
WriteLn(St);
Y:=WhereY;
X:=II-3; if X<1 then X:=1;
GotoXY(X, Y);
Write('^');
if S[0]>#0 then NewS:='Error, '+S else NewS:='Error';
if X+Ord(NewS[0])>80 then X:=X-Ord(NewS[0]) else X:=X+1;
GotoXY(X,Y); WriteLn(NewS);
ErrCount:=Succ(ErrCount);
if ErrCount>6 then
begin
WriteLn('Excessive Number of Errors');
Halt(1);
end;
end;
PROCEDURE ByteErr; Forward;
PROCEDURE NumbyteErr; Forward;
{$I unpars.inc}
{-------------InsrtChr}
PROCEDURE InsrtChr(C :Char);
begin
Ustring.S[UsIndex]:=C;
if Ustring.Len<UsIndex then Ustring.Len:=UsIndex;
UsIndex:=UsIndex+1;
end;
{-------------Comma}
PROCEDURE Comma;
begin InsrtChr(','); end;
{-------------InsrtSt}
PROCEDURE InsrtSt(S :String127);
Var K :Integer;
begin
for K:=1 to Ord(S[0]) do
begin
InsrtChr(S[K]);
end;
end;
Type String4=String[4];
{-------------Hex2}
FUNCTION Hex2(B :Byte): String4;
Const HexDigs :Array[0..15] of Char = '0123456789ABCDEF';
Var Bz :Byte;
begin
Bz:=B and $F; B:=B Shr 4;
Hex2:=HexDigs[B]+HexDigs[Bz];
end;
{-------------Hex4}
FUNCTION Hex4(W :Integer): String4;
begin Hex4:=Hex2(Hi(W))+Hex2(Lo(W)); end;
{-------------Insrthx2}
PROCEDURE Insrthx2(B :Byte);
begin
InsrtChr('$');
InsrtSt(Hex2(B));
end;
{-------------Insrthx4}
PROCEDURE Insrthx4(W :Word);
begin
InsrtChr('$');
InsrtSt(Hex4(W));
end;
{-------------InsrtDisp}
PROCEDURE InsrtDisp(Disp : Packet);
begin
with Disp do
if not Phrase then
begin
if (Dispsize=Bytesize) then
begin
if Value and $80 <>0 then
begin
InsrtChr('-'); {turn into negative number}
Value:=-(Value or $FF00);
end
else InsrtChr('+');
Insrthx2(Lo(Value));
end
else
Insrthx4(Value);
end
else InsrtSt(S);
end;
{-------------FormLabel}
FUNCTION FormLabel(N : Integer): String8;
Var S : String8;
begin
Str(N,S);
FormLabel:='X'+S;
end;
{-------------OutLabel}
PROCEDURE OutLabel(N : Integer);
PROCEDURE AddLabel(N : Integer);
Var I : Integer; Fnd : Boolean;
begin
Fnd:=False; {only add label if it isn't already there}
I:=0;
while (I<LabelIndx) and not Fnd do
begin Fnd:=Labels[I].PCvalue=N; I:=Succ(I); end;
if not Fnd then
if LabelIndx<=MaxLabels then
with Labels[LabelIndx] do
begin
PCvalue:=N;
Found:=False; {will try to find it later}
LabelIndx:=Succ(LabelIndx);
end;
end;
begin
AddLabel(N);
InsrtSt(FormLabel(N));
end;
{-------------ByteErr}
PROCEDURE ByteErr;
begin
Error(Chi,'Byte Exp');
Next; {pass it by}
PC:=Succ(PC);
end;
{-------------NumbyteErr}
PROCEDURE NumbyteErr;
begin
Error(Chi,'Numerical Byte Exp');
Next; {pass it by}
PC:=Succ(PC);
end;
{-------------ShortJump}
PROCEDURE ShortJump;
{the short jump instructions}
Var Pk : Packet;
Vl : Word;
begin
if not GetByte(Pk,PhraseOk) then ByteErr;
if (Opcode=$EB) then InsrtSt('SHORT ');
with Pk do
if not Phrase then
begin
Vl:=Value;
if (Vl and $80 <>0) then Vl:=Vl or $FF00; {sign extend}
Vl:=Vl+PC;
OutLabel(Vl);
end
else InsrtDisp(Pk);
end;
{-------------IntraSeg}